package com.itheima.d2_recursion;

import java.io.File;

public class Test5 {
    public static void main(String[] args) {
        //删除非空文件夹，独立功能独立方法
        File dir = new File("D:\\a");
        deleteDir(dir);
    }

    private static void deleteDir(File dir) {
        if(dir == null || !dir.exists()) return;
        if(dir.isFile()){
            dir.delete();
            return;
        }

        File[] files = dir.listFiles();
        if (files == null) {
            return;
        }
        for (File file : files) {
            if(file.isFile()){
                file.delete();
            }else{
                deleteDir(file);
            }
        }
        dir.delete();
    }
}
